package com.alks.function.controller.finance.lotcost;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.AutoPageAop;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.enums.LaborTypeEnum;
import com.alks.entity.data.enums.MtlEnum;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.finance.lotcost.LotCostRequest;
import com.alks.function.data.vo.finance.lotcost.*;
import com.alks.function.data.vo.finance.lotcost.h5.LotCostAnalysisDetailH5VO;
import com.alks.function.data.vo.finance.lotcost.h5.LotCostAnalysisListH5VO;
import com.alks.function.data.vo.finance.lotcost.h5.LotCostAnalysisStatisticH5VO;
import com.alks.function.data.vo.stock.PageDataVO;
import com.alks.function.service.finance.lotcost.ILotCostAnalysisService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author: chen
 * @date: 2025/02/10
 * @description: 指令成本分析移动端接口
 */
@Slf4j
@RestController
@AllArgsConstructor
@ApiRestController("/lotCost/analysis/h5")
@Api(value = "指令成本分析", tags = "移动端指令成本分析")
public class LotCostAnalysisForH5Controller {

    final private ILotCostAnalysisService lotCostAnalysisService;

    @WebLogger
    @PostMapping("/listPage")
    @ApiOperation(value = "分页查询", tags = "移动端指令成本分析")
    @AutoPageAop
    public ResponseInfo<PageDataVO<LotCostAnalysisListH5VO>> tempQuery(@RequestBody LotCostRequest request) {
        PageDataVO<LotCostAnalysisListH5VO> res = new PageDataVO<>();
        List<LotCostAnalysisListH5VO> list = lotCostAnalysisService.tempQueryForH5(request);
        Page<LotCostAnalysisListH5VO> page = (Page<LotCostAnalysisListH5VO>) list;
        res.setRows(list);
        res.setTotal(page.getTotal());
        return ResponseInfo.ok(res);
    }

    @WebLogger
    @GetMapping("/detail")
    @ApiOperation(value = "基本数据", tags = "移动端指令成本分析")
    public ResponseInfo<LotCostAnalysisDetailH5VO> detail(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.detailForH5(lotNo));
    }

    @WebLogger
    @GetMapping("/statistic")
    @ApiOperation(value = "成本统计", tags = "移动端指令成本分析")
    public ResponseInfo<LotCostAnalysisStatisticH5VO> statistic(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.statisticForH5(lotNo));
    }

    @WebLogger
    @GetMapping("/upper/list")
    @ApiOperation(value = "面材明细（含多购）", tags = "移动端指令成本分析")
    public ResponseInfo<Map<String, Object>> upperList(@RequestParam String lotNo) {
        List<ReportMtlDetailVO> upperMtlItems = lotCostAnalysisService.getCostDetail(lotNo, MtlEnum.TYPE_UPPER.getValue(), null);
        List<ReportMtlDetailVO> upperMtlMulItems = lotCostAnalysisService.getCostDetail(lotNo, MtlEnum.TYPE_UPPER2.getValue(), null);
        Map<String, Object> res = new HashMap<>(2);
        res.put("upper", upperMtlItems);
        res.put("upperMul", upperMtlMulItems);
        return ResponseInfo.ok(res);
    }

    @WebLogger
    @GetMapping("/pack/list")
    @ApiOperation(value = "包材明细", tags = "移动端指令成本分析")
    public ResponseInfo<List<ReportMtlDetailVO>> packList(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.getCostDetail(lotNo, MtlEnum.TYPE_PACK.getValue(), null));
    }

    @WebLogger
    @GetMapping("/sole/list")
    @ApiOperation(value = "大底明细", tags = "移动端指令成本分析")
    public ResponseInfo<List<ReportMtlDetailVO>> soleMtlList(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.getCostDetail(lotNo, MtlEnum.TYPE_SOLE.getValue(), MtlEnum.PART_SOLE.getValue()));
    }

    @WebLogger
    @GetMapping("/sole2/list")
    @ApiOperation(value = "面衬明细", tags = "移动端指令成本分析")
    public ResponseInfo<List<ReportMtlDetailVO>> soleMtl2List(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.getCostDetail(lotNo, MtlEnum.TYPE_SOLE.getValue(), MtlEnum.PART_FACE.getValue()));
    }

    @WebLogger
    @GetMapping("/cut/list")
    @ApiOperation(value = "冲裁人工明细", tags = "移动端指令成本分析")
    public ResponseInfo<List<ReportLaborDetailVO>> cutList(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.getLaborDetail(lotNo, LaborTypeEnum.CUT.getValue()));
    }

    @WebLogger
    @GetMapping("/manual/list")
    @ApiOperation(value = "手工人工明细", tags = "移动端指令成本分析")
    public ResponseInfo<List<ReportLaborDetailVO>> manualList(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.getLaborDetail(lotNo, LaborTypeEnum.MANUAL.getValue()));
    }

    @WebLogger
    @GetMapping("/out/list")
    @ApiOperation(value = "外协人工明细", tags = "移动端指令成本分析")
    public ResponseInfo<List<ReportLaborDetailVO>> outList(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.getLaborDetail(lotNo, LaborTypeEnum.OUT.getValue()));
    }

    @WebLogger
    @GetMapping("/stitch/list")
    @ApiOperation(value = "针车人工明细", tags = "移动端指令成本分析")
    public ResponseInfo<List<ReportLaborDetailVO>> stitchList(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.getLaborDetail(lotNo, LaborTypeEnum.STITCH.getValue()));
    }

    @WebLogger
    @GetMapping("/supplementDuty/list")
    @ApiOperation(value = "补单明细", tags = "移动端指令成本分析")
    public ResponseInfo<List<SupplementDutyVO>> supplementDutyList(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.getSupplementDutyDetail(lotNo));
    }

    @WebLogger
    @GetMapping("/other/list")
    @ApiOperation(value = "其他明细", tags = "移动端指令成本分析")
    public ResponseInfo<List<OtherFeeVO>> otherList(@RequestParam String lotNo) {
        return ResponseInfo.ok(lotCostAnalysisService.getOtherFeeDetail(lotNo));
    }
}
